home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1794 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  994 b 

  1. Path: news.bridge.net!news
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: copy ctor and derived classes
  5. Date: 13 Jan 1996 00:24:07 GMT
  6. Organization: self-employed
  7. Message-ID: <4d6u37$3b7@news.bridge.net>
  8. References: <DL38zz.50K@Virginia.EDU>
  9. NNTP-Posting-Host: ppp-mia1-64.bridge.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15.  
  16. Greg;
  17.  
  18. >>  how can I invoke the base class's copy constructor in the
  19. >> intialization list the derived class doesn't have to deal 
  20. >> with all of the little bits of the base class?
  21.  
  22.  
  23. The derived class has no RIGHT to deal with all the bits of the 
  24. base class. They can be private.
  25.  
  26. Here's what to do:
  27.  
  28.  
  29. Derived::Derived( const Derived& rhs )      // copy ctor
  30.  : Base( *this )                           // invoke base's copy ctor
  31. {
  32.  
  33. }
  34.  
  35.  
  36. The copy ctor which the compiler can silently fgenerate for you,will do 
  37. this a utomatically.
  38.  
  39.